package com.zjuee.base.exception;


import com.zjuee.base.bean.response.ResultCode;

/**
 * 基本异常类型
 * 所有自定义异常，都应该实现ResultCode接口，拦截器中会根据异常类型动态返回错误信息
 *
 * @author wu liang
 * @since 1.0
 */
public class BaseException extends RuntimeException implements ResultCode {

    protected String code;
    private String msg;


    public BaseException(ResultCode resultCode){
        super(resultCode.getMsg());
        if (resultCode.getCode() != null) {
            this.code = resultCode.getCode();
            this.msg = resultCode.getMsg() == null ? "" : resultCode.getMsg();
        }
    }

    public BaseException(ResultCode resultCode, String msg){
        super(msg);
        if (resultCode != null) {
            this.code = resultCode.getCode();
            this.msg = msg;
        }
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getMsg() {
        return this.msg;
    }
}
